﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Xunit;
using YAPL.Language.Ast;
using YAPL.Language.SourceParser.XML;

namespace YAPL.Test.YAPL.Language.Parser.XML.NodeParsers {
	public class XmlVariableParserTest : XmlNodeParserTest {

		[Fact]
		public void VariableShouldHaveNameAttribute() {
			var variableNode = new XElement(XmlNames.VariableExpression);
			Assert.Throws<ArgumentNullException>(() => _parser.ParseNode(variableNode));
		}

		[Fact]
		public void VariableNameShouldNotBeEmpty() {
			var variableNode = new XElement(XmlNames.VariableExpression, new XAttribute(XmlNames.IdentifierNameAttribute, ""));
			Assert.Throws<ArgumentException>(() => _parser.ParseNode(variableNode));
		}

		[Fact]
		public void VariableWithNameShouldBeParsedCorrectly() {
			var variableNode = new XElement(XmlNames.VariableExpression, new XAttribute(XmlNames.IdentifierNameAttribute, "a"));
			Expression expr = null;
			Assert.DoesNotThrow(() => expr = _parser.ParseNode(variableNode));
			Assert.IsType(typeof (VariableExpression), expr);
			var variable = (VariableExpression) expr;
			Assert.Equal("a", variable.Name);
		}
	}
}
